const webpack = require('webpack');
const path = require('path');

//清理文件夹
const CleanPlugin = require('clean-webpack-plugin');
//将模板加载bundle
const HtmlWebpackPlugin = require('html-webpack-plugin');
//抽出CSS
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    devtool: 'source-map',
    entry: {
        main: path.resolve(__dirname, 'app/main.js'),
        vendor: ['react', 'react-dom', 'amazeui-touch', 'react-addons-css-transition-group']
    },
    output: {
        path: path.resolve(__dirname, './build'),
        filename: 'scripts/[name].[chunkhash].js'
    },
    module: {
        // preLoaders: [{
        //     test: /\.js$/,
        //     include: './src/',
        //     exclude: ['./src/jquery.min.js', './src/echarts.min.js'],
        //     loader: 'eslint-loader'
        // }],
        loaders: [{
            test: /\.jsx?$/,
            include: [
                path.join(__dirname, './app'),
                path.resolve(__dirname, "./node_modules/amazeui-touch/js")
            ],
            loader: 'babel?presets[]=es2015-loose&presets[]=react'
        }, {
            test: /\.css$/,
            // loader: ExtractTextPlugin.extract('style', "css")
            loader: 'style!css'
        }, {
            test: /\.scss$/,
            // loader: ExtractTextPlugin.extract('style', "css!sass")
            loader: 'style!css!sass'
        }, {
            test: /\.(png|jpg|gif)$/,
            loader: 'url-loader?limit=4096&name=img/[name].[hash].[ext]'
        }, {
            test: /\.(ttf|woff|woff2|svg|eot)$/,
            loader: 'file-loader?name=fonts/[name].[hash].[ext]'
        }]
    },
    plugins: [
        new CleanPlugin(['build']),
        new webpack.optimize.CommonsChunkPlugin( /* chunkName= */ 'vendor', /* filename= */ 'scripts/vendor.[chunkhash].js'),
        new HtmlWebpackPlugin({
            template: 'html-withimg-loader!./index.html',
            filename: 'index.html'
        }),
        // new ExtractTextPlugin("styles/[name].[hash].css"),
        new webpack.optimize.UglifyJsPlugin({
            minimize: true,
            compress: {
                warnings: false,
            },
        }),
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        })
    ]
};